package com.thesis.teacher.controller;

import com.alibaba.fastjson.JSONObject;
import com.thesis.manage.common.utils.Result;
import com.thesis.manage.domain.Teacher;
import com.thesis.manage.service.StudentThesisService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author php
 * @date 2018/3/27
 */
@RequestMapping("/student/thesis")
@RestController
public class StudentThesisController extends BaseController {
    @Resource
    private StudentThesisService studentThesisService;

    /**
     * 学生申报论题审核列表
     **/
    @GetMapping("/list")
    public Map<String, Object> list() {
        return buildMessage(() -> {
            Result result = getUser();
            Teacher teacher = JSONObject.parseObject(result.getData().toString(), Teacher.class);
            return studentThesisService.reviewThesis(teacher.getTeacherNumber());
        });
    }

    /**
     * 申报题目审核
     *
     * @param id      论题id
     * @param status  状态
     * @param message 消息体
     */
    @PostMapping("/adopt")
    public Map<String, Object> adopt(Long id, Integer status, @RequestParam(required = false, defaultValue = "审核通过") String message) {
        return buildMessage(() -> {
            studentThesisService.adopt(id, status, message);
            return null;
        });
    }

    /**
     * 学生选题审核
     *
     * @param id      论题id
     * @param status  状态
     * @param message 消息体
     */
    @PostMapping("/selectThesis/adopt")
    public Map<String, Object> selectThesisAdopt(Long id, Integer status, @RequestParam(required = false, defaultValue = "审核通过") String message) {
        return buildMessage(() -> {
            Result result = getUser();
            Teacher teacher = JSONObject.parseObject(result.getData().toString(), Teacher.class);
            studentThesisService.selectThesisAdopt(id, status, message, teacher.getName());
            return null;
        });
    }
}
